package com.sqlist.shareserver.connection;

import io.netty.channel.Channel;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

@Component
public class ConnectionPool {
    private final ConcurrentHashMap<String, Channel> userMap = new ConcurrentHashMap<>();

    public Channel getChannel(String username) {
        return userMap.get(username);
    }

    public void removeChannel(String username) {
        userMap.remove(username);
    }

    public void removeChannel(Channel channel) {
        userMap.remove(channel);
    }

    public void addChannel(String username, Channel channel) {
        userMap.put(username, channel);
    }

    public ConcurrentHashMap<String, Channel> getUserMap() {
        return userMap;
    }
}
